package co.edu.unal.bioingenium.kbmed.web.listener;

import co.edu.unal.bioingenium.kbmed.knowledge.KnowledgeService;
import co.edu.unal.bioingenium.kbmed.knowledge.dao.KnowledgeSourceDAO;
import co.edu.unal.bioingenium.kbmed.knowledge.dao.KnowledgeSourceDAOFactory;
import co.edu.unal.bioingenium.kbmed.knowledge.hierarchy.HierarchyService;
import co.edu.unal.bioingenium.kbmed.knowledge.visualization.VisualizationService;
import co.edu.unal.bioingenium.kbmed.retrieval.knowledge.process.RetrieveService;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 *
 * @author alejandro
 */
public class ContextLoaderListener implements ServletContextListener {

    /**
     *
     * @param sce
     */
    public void contextInitialized(ServletContextEvent sce) {
        Logger.getLogger(ContextLoaderListener.class.getName()).log(Level.INFO, "Initializing kbmed-web context");
        RetrieveService.getInstance();
        VisualizationService.getInstance();
        KnowledgeService knowledgeService = KnowledgeService.getInstance();
        KnowledgeSourceDAO knowledgeSourceDAO = KnowledgeSourceDAOFactory.getKnowledgeSourceDAO();
        Set<String> categories = knowledgeSourceDAO.getCategories();
        for (String category : categories) {
            HierarchyService.getInstance().initHierarchy(category);
        }
    }

    /**
     *
     * @param sce
     */
    public void contextDestroyed(ServletContextEvent sce) {
        Logger.getLogger(ContextLoaderListener.class.getName()).log(Level.INFO, "contextDestroyed called");
    }
}
